const {createApp} = Vue;
const {ref} = Vue;
const {reactive} = Vue;
const {onMounted} = Vue;
const {createRouter} = VueRouter;
const {createStore}=Vuex;
const{ElMessage}=ElementPlus;
//创建Vue Router实例
const router = createRouter({
      history: VueRouter.createWebHashHistory(),
      routes: [
		{ path: '/', redirect: '/Login' },//默认页面
        { path: '/Default', component: Default },//空页面
        { path: '/MainProgram', component: MainProgram },//主程序页面
		{ path: '/Login',component: Login},//登陆页面
      ]
    });
//路由守卫 禁止登陆完成的用户跳转回登陆界面
router.beforeEach((to, from, next) => {
	if (from.path=='/MainProgram'&&to.path=='/Login'&&store.state.isLogin)
	{ 
		next(false);
	} 
	else
	{
		next();
	}
})
//创建Vuex store实例
const store = createStore({
  state () {
    return {
      Token: 0,
	  isLogin: false, 
    }
  },
  mutations: {
	  UpToken(state,n){
		  state.Token=n;
		  //更新Token令牌
	  },
	  UpLogin(state,n){
          state.isLogin=n;
		}//更新登录状态，如果Token存在，则isLogin为true，否则为false。
  }
});
//创建Vue实例
const app = createApp({
	setup(){
		onMounted(() => {
			router.push('/');
		})
	}
});
//注册elementui icon全局组件
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
	app.component(key, component)
};
//注册elementplus
app.use(ElementPlus, {
	locale: ElementPlusLocaleZhCn
});
//注册路由
app.use(router);
//注册store
app.use(store);
//挂载app
app.mount('#app');